package orchestration.businessprocess.model.nodes;

import java.util.Set;

import orchestration.businessprocess.model.BPArtifact;
import orchestration.businessprocess.model.BPNodeId;

/**
 * Class that wraps logic to create and concat nodes
 * @author <a href="mailto:car.ferrarini@gmail.com">Carlo Ferrarini</a>
 *
 */
public class BPNodesManager {
	
	
	
	public static BPNode createBPTask(BPNodeId id, Set<BPArtifact> input, Set<BPArtifact> output){
		return new BPTask(id,input,output);
	}
	public static BPNode createBPLoopingTask(BPNodeId id, Set<BPArtifact> input, Set<BPArtifact> output,String loopingExpression){
		BPTask task= new BPTask(id,input,output);
		task.setLoopingExpression(loopingExpression);
		return task;
	}
	
	public static BPNode createBPStartEvent(BPNodeId id, Set<BPArtifact> output){
		return new BPStartEvent(id,output);
	}
	
	public static BPNode createBPEndEvent(BPNodeId id, Set<BPArtifact> input){
		return new BPEndEvent(id,input);
	}
	
	public static BPNode createBPIntEvent(BPNodeId id,Set<BPArtifact> input, Set<BPArtifact> output){
		return new BPIntEvent(id,input,output);
	}
	
	public static BPNode createBPJoinGateway(BPNodeId id){
		return new BPJoinGateway(id);
	}
	
	public static BPNode createBPMergeGateway(BPNodeId id){
		return new BPMergeGateway(id);
	}
	
	public static BPNode createBPForkGateway(BPNodeId id){
		return new BPForkGateway(id);
	}
	public static BPNode createBPExGateway(BPNodeId id,Set<BPArtifact> input){
		return new BPExGateway(id,input);
	}
	/**
	 * concat nodes verifying their type
	 * @param src
	 * @param trt
	 * @param condition
	 */
	public static void concat(BPNode src, BPNode trt,String condition){
		switch (src.getNodeType()) {
		case BPNode.NODE_TYPE_FGW:((BPForkGateway)src).addNext(trt);
			break;
		case BPNode.NODE_TYPE_EGW: ((BPExGateway)src).addNext(trt,condition);
			break;
		case BPNode.NODE_TYPE_INT_EV:((BPIntEvent)src).setNext(trt);
			break;
		case BPNode.NODE_TYPE_ST_EV: ((BPStartEvent)src).setNext(trt);
			break;
		case BPNode.NODE_TYPE_TASK:((BPTask)src).setNext(trt);
			break;
		case BPNode.NODE_TYPE_JGW:((BPJoinGateway)src).setNext(trt);
			break;
		case BPNode.NODE_TYPE_MGW:((BPMergeGateway)src).setNext(trt);
			break;
		default:
			break;
		}
		if(trt.getNodeType()==BPNode.NODE_TYPE_JGW)
			((BPJoinGateway)trt).addPrev(src);
	}
}
